extends CenterContainer


var edit_data = null

onready var name_input = $PanelContainer/VBoxContainer/name/LineEdit
onready var icon_input = $PanelContainer/VBoxContainer/icon/LineEdit
onready var desc_input = $PanelContainer/VBoxContainer/desc/TextEdit

onready var levle_input = $PanelContainer/VBoxContainer/level/SpinBox
onready var hide_op = $PanelContainer/VBoxContainer/hide/OptionButton

signal close


func set_edit_data(data):
	self.edit_data = data

	
	if edit_data:
		name_input.text = data["name"]
		desc_input.text = data["description"]
		levle_input.value = data["maxCatchLevel"]
		icon_input.text = data.get("icon", "")
		
		
		hide_op.select(hide_op.get_item_index(data["hide"]))
	

func _on_cancel_button_up():
	MainTool.getUILayer().pop_ui()


func _on_ok_button_up():
	if edit_data:
		edit_data["name"] = name_input.text
		edit_data["description"] = desc_input.text
		edit_data["icon"] = icon_input.text
		edit_data["maxCatchLevel"] = levle_input.value
		
		edit_data["hide"] = hide_op.get_selected_id()
			
		DataSource.update_data(DataSource.gyms, edit_data)
		
		MainTool.toast_info("更新成功!")
	else:
		var data = {
			"name": name_input.text,
			"icon": icon_input.text,
			"description": desc_input.text,
			"maxCatchLevel": levle_input.value,
			"hide": hide_op.get_selected_id()
		}
		
		DataSource.add_data(DataSource.gyms, data)
	
		MainTool.toast_info("添加成功!")
	
	MainTool.getUILayer().pop_ui()
	
	emit_signal("close")
